// asyncLocalStory(key,user);

var user = [
    {
        id: 1,
        name: '王先生',
        phone: '1539013518',
        businessName: '宏基企业',
        businessType: '一般企业',
        inTentType: '租房',
        InvestmentPer: '李四',
        ApprovalStatus: '签约待审核',
        SubmissionTime: '2022-09-09 12:23:23',
        ApprovalProcess: '待XXX审核',
        ApprovalTime: '2022-09-09 12:23:23'
    },
    {
        id: 2,
        name: '侯先生',
        phone: '1539013518',
        businessName: '宏基企业',
        businessType: '一般企业',
        inTentType: '卖房',
        InvestmentPer: '李四',
        ApprovalStatus: '签约待审核',
        SubmissionTime: '2022-09-09 12:23:23',
        ApprovalProcess: '待XXX审核',
        ApprovalTime: '2022-09-09 12:23:23'
    },
    {
        id: 3,
        name: '李先生',
        phone: '1539013518',
        businessName: '宏基企业',
        businessType: '一般企业',
        inTentType: '租房',
        InvestmentPer: '王五',
        ApprovalStatus: '签约已拒绝',
        SubmissionTime: '2022-09-09 12:23:23',
        ApprovalProcess: '待XXX审核',
        ApprovalTime: '2022-09-09 12:23:23'
    },
    {
        id: 4,
        name: '聂老八',
        phone: '1539013518',
        businessName: '宏基企业',
        businessType: '一般企业',
        inTentType: '租房',
        InvestmentPer: '王五',
        ApprovalStatus: '已签约',
        SubmissionTime: '2022-09-09 12:23:23',
        ApprovalProcess: '待XXX审核',
        ApprovalTime: '2022-09-09 12:23:23'
    }
];

var place = [
    {
        id: 1,
        PrincipalName: '原生广场',
        displayStatus: '显示',
        remark: '无备注',
        RegionName: 'A区',
        introduce:''
    },
    {
        id: 2,
        PrincipalName: '民生广场',
        displayStatus: '显示',
        remark: '无备注',
        RegionName: 'B区',
        introduce:''
    },
    {
        id: 3,
        PrincipalName: '土生广场',
        displayStatus: '未显示',
        remark: '无备注',
        RegionName: 'B区',
        introduce:''
    },
    {
        id: 4,
        PrincipalName: '王生广场',
        displayStatus: '未显示',
        remark: '无备注',
        RegionName: 'B区',
        introduce:''
    },
    {
        id: 5,
        PrincipalName: '原生广场',
        displayStatus: '显示',
        remark: '无备注',
        RegionName: 'A区',
        introduce:''
    },
    {
        id: 6,
        PrincipalName: '民生广场',
        displayStatus: '显示',
        remark: '无备注',
        RegionName: 'B区',
        introduce:''
    },
    {
        id: 7,
        PrincipalName: '土生广场',
        displayStatus: '未显示',
        remark: '无备注',
        RegionName: 'B区',
        introduce:''
    },
    {
        id: 8,
        PrincipalName: '王生广场',
        displayStatus: '未显示',
        remark: '无备注',
        RegionName: 'B区',
        introduce:''
    },
    {
        id: 9,
        PrincipalName: '原生广场',
        displayStatus: '显示',
        remark: '无备注',
        RegionName: 'A区',
        introduce:''
    },
    {
        id: 10,
        PrincipalName: '民生广场',
        displayStatus: '显示',
        remark: '无备注',
        RegionName: 'B区',
        introduce:''
    },
    {
        id: 11,
        PrincipalName: '土生广场',
        displayStatus: '未显示',
        remark: '无备注',
        RegionName: 'B区',
        introduce:''
    },
    {
        id: 12,
        PrincipalName: '王生广场',
        displayStatus: '未显示',
        remark: '无备注',
        RegionName: 'B区',
        introduce:''
    }
];


let  house = [
    {
        id: 1,
        houseNumber: '12345',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 2,
        houseNumber: '12345333',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 3,
        houseNumber: '12342342345',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 4,
        houseNumber: '123423425',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 5,
        houseNumber: '12323423423445',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 6,
        houseNumber: '12342342345',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 7,
        houseNumber: '12345234',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 8,
        houseNumber: '12323445',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 9,
        houseNumber: '12342345',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 10,
        houseNumber: '12345234234',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 11,
        houseNumber: '123423445',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    },
    {
        id: 12,
        houseNumber: '12345234234',
        PrincipalName: '民生广场',
        RegionName: 'A区',
        HouseName:'豪华办公室',
        HousingType:'房间',
        BuildingCondition:'空置',
        TypeOfLeaseAndSale:'出租',
        area: '30',
        remark: '无备注'
    }
];
//捕获异常
// try {
//     //代码执行正确
//     return true
// } catch (e) {
//     //错误
//     return false;
// }

// asyncLocalStory(key);

//



window.onload = function () {
    // showData();
    add();
    getData();
}
$("#tbCard").on("click", ".del", function () {
    console.log(this);
    //获取数据
    let data = getData();
    for (let i = 0; i < data.length; i++) {
        let id = $(this).attr("data-index");
        console.log(id);
        //判断
        if (data[i].id == id) {
            data.splice(i, 1);
        }
        saveData(data);
        showData()
    }
});

//判断是否加载
function add() {
    if (getData().length == 0) {
        saveData(place);
    }
}

function saveData(data) {
    sessionStorage.setItem("place", JSON.stringify(data));
}
function getData() {
    let data = sessionStorage.getItem("place");
    if (data !== null) {
        return JSON.parse(data);
    } else {
        return [];
    }
}
// function showData() {
//     let data1 = getData();
//     $("#tbCard").empty();
//     let fragment1 = document.createDocumentFragment();
//     $.each(data1, function (i, n) {
//         $("#tbCard").html = "";
//         let tr = document.createElement("tr");
//         tr.innerHTML = `
//             <td><input type="checkbox"/></td>
//                     <td>${n.id}</td>
//                     <td>${n.name}</td>
//                     <td>${n.phone}</td>
//                     <td>${n.businessName}</td>
//                     <td>${n.businessType}</td>
//                     <td>${n.inTentType}</td>
//                     <td>${n.InvestmentPer}</td>
//                     <td>${n.ApprovalStatus}</td>
//                     <td>${n.SubmissionTime}</td>
//                     <td>${n.ApprovalProcess}</td>
//                     <td>${n.ApprovalTime}</td>
//                     <td>
//                         <button class = "modify">编辑</button>
//                         <button class = "del" data-index='${n.id}'>删除</button>
//                     </td>
//             `;
//         fragment1.appendChild(tr);
//     })
//     $("#tbCard").append(fragment1);
// }